// 全局修改方法
export const useTheme = () => {
  const visibility = useDocumentVisibility()
  const userStore = useUserStore()
  const route = useRoute()
  const { endLoading } = useFullLoading()
  // 初始化执行
  const initLayoutTheme = () => {
    initVisibility() //其他操作
  }
  //初始化阻止浏览器右键功能
  const initVisibility = () => {
    // 监听是否在这个页面上
    watch(visibility, (newValue) => {
      if (
        !userStore.userInfo?.username ||
        newValue === 'hidden' ||
        route.fullPath.includes('/login')
      ) {
        return
      }
      ElNotification({
        message: `尊敬的${userStore.userInfo?.username}，欢迎回来`,
        type: 'success',
        position: 'bottom-right',
      })
    })
  }
  // 监听全局loading状态
  watch(
    () => route.fullPath,
    (newValue: string) => {
      !newValue.includes('/login') && window.nextLoading && endLoading(500)
    },
    {
      deep: true,
    },
  )
  return {
    initLayoutTheme,
  }
}
